package net.fdukedom.epicurus.service;

import net.fdukedom.epicurus.service.interaction.IdentificationRequest;
import net.fdukedom.epicurus.service.interaction.IdentificationRequestReader;
import net.fdukedom.epicurus.service.interaction.ResponseWriter;

public abstract class WSMessageHandler implements WSMessageHandlerInterface {

	/**
	 * Process user request
	 */
	public String process(String request) {
		IdentificationRequestReader requestReader = new IdentificationRequestReader(
				request);
		System.out.println(requestReader.getID());

		if (requestReader.getID().equals(IdentificationRequest.ID_UPDATE)) {
			return processUpdate(requestReader);
		} else if (requestReader.getID()
				.equals(IdentificationRequest.ID_COMMIT)) {
			return processCommit(requestReader);
		}

		ResponseWriter response = new ResponseWriter();

		response.setMessage("Unknown request id: " + requestReader.getID());
		response.setStatus(false);

		return response.toString();
	}

	protected abstract String processUpdate(IdentificationRequestReader request);

	protected abstract String processCommit(IdentificationRequestReader request);
}
